Next | Prev | Up | Top | Contents | Index

Mapping PIO Addresses

A PIO map is a system object that represents the mapping of a location in kernel virtual memory to some range of addresses on a VME or EISA bus. After creating a PIO map, a device driver can use it in the following ways:

The functions used with PIO maps are summarized in Chapter 17, "EISA Device Drivers.".

Functions to Create and Use PIO Maps
FunctionHeader FilesCan SleepPurpose
pio_mapalloc(D3) pio.h & types.hYAllocate a PIO map.
pio_mapfree(D3) pio.h & types.hNFree a PIO map.
pio_badaddr(D3) pio.h & types.hNCheck for bus error when reading an address.
pio_wbadaddr(D3) pio.h & types.hNCheck for bus error when writing to an address.
pio_mapaddr(D3) pio.h & types.hNConvert a bus address to a virtual address.
pio_bcopyin(D3) pio.h & types.hYCopy data from a bus address to kernel's virtual space.
pio_bcopyout(D3) pio.h & types.hYCopy data from kernel's virtual space to a bus address.
pio_andb_rmw(D3) pio.h & types.hNByte read-AND-write cycle.
pio_andh_rmw(D3) pio.h & types.hN16-bit read-AND-write cycle.
pio_andw_rmw(D3) pio.h & types.hN32-bit read-AND-write cycle.
pio_orb_rmw(D3) pio.h & types.hNByte read-OR-write cycle.
pio_orh_rmw(D3) pio.h & types.hN16-bit read-OR-write cycle.
pio_orw_rmw(D3) pio.h & types.hN32-bit read-OR-write cycle.

A kernel-level device driver creates a PIO map by calling pio_mapalloc(). This function performs memory allocation and so can sleep. PIO maps are typically created in the pfxedtinit() entry point, where the driver first learns about the device addresses from the contents of the edt_t structure (see "Entry Point edtinit()").

The parameters to pio_mapalloc() describe the range of addresses that can be mapped in terms of

This call also specifies a "fixed" or "unfixed" map. This distinction applies only to VME maps. An EISA map is always a fixed map.

A call to pio_mapfree() releases a PIO map. PIO maps created by a loadable driver must be released in the pfxunload() entry point (see "Entry Point unload()" and "Unloading").


Testing the PIO Map

The PIO map is created from the parameters that are passed. These are not validated by pio_mapalloc(). If there is any possibility that the mapped device is not installed, not active, or improperly configured, you should test the mapped address.

The pio_baddr() and pio_wbaddr() functions test the mapped address to see if it is usable.


Using the Mapped Address

From a fixed PIO map you can recover a kernel virtual address that corresponds to the first bus address in the map. The pio_mapaddr() function is used for this.

You can use this address to load or store data into device registers. In the pfxmap() entry point (see "Concepts and Use of mmap()"), you can use this address with the v_mapphys() function to map the range of device addresses into the address space of a user process.


Using the PIO Map in Functions

You can apply a variety of kernel functions to any PIO map, fixed or unfixed. The pio_bcopyin() and pio_bcopyout() functions copy a range of data between memory and a PIO map. There is no performance advantage to using these functions, as compared to loading or storing to the mapped addresses, but their use makes the device driver code simpler and more readable.

The series of functions pio_andb_rmw() and pio_orb_rmw() perform a read-modify-write cycle. You can use them to set or clear bits in device registers. Read-modify-write cycles on the EISA bus are atomic operations to software only (see "EISA Locked Cycles").


Next | Prev | Up | Top | Contents | Index